package com;

import java.util.ArrayList;

import sun.jdbc.rowset.CachedRowSet;
import util.ClobUtil;
import util.mysql;
import util.oracle;

public class news {
    public static void main(String args[]) {
        oracle o = new oracle();
        mysql m = new mysql();
        try {
            int all = 0;
            long start = System.currentTimeMillis();
            CachedRowSet count = o.executeQuery("select count(id) as count from news");
            if (count.next()) {
                all = count.getInt("count");   
            }
            ArrayList < String > list = new ArrayList < String > ();
            for (int a = 1, b = 1; a <= all; a++) {
                if (a % 300 == 0 || a == all) {

                    list.clear();
                    String sql = "select t.* from(select a.id,\n" + "a.title,1 as fff,\n" + "a.adddate,\n" + "a.yhdm,\n" + "a.lastdate,\n" + "a.lastyhdm,\n" + "a.isdelete,\n" + "a.clickcount,\n" + "a.type,\n" + "a.shortcontent,\n" + "a.shenhe,\n" + "a.istop,\n" + "a.haspics,\n" + "a.ishot,\n" + "a.leixing,\n" + "a.zhiding,\n" + "a.tuijian,\n" + "a.tuijiantime,\n" + "a.last_content,\n" + "a.last_adddate,\n" + "a.last_yhdm,\n" + "a.last_yhmc,rownum rn from news a )t where t.rn>=" + b + " and t.rn<=" + a;
                    CachedRowSet rs = o.executeQuery(sql);
                    ClobUtil clob = new ClobUtil();
                    while (rs.next()) {
                        list.add("INSERT INTO `news` VALUES (" + get(rs.getString(1)) + "," + get(rs.getString(2)) + "," + get(clob.readClob(rs.getString(1) + "", "news", "id", "content")) + "," + get(rs.getString(4)) + "," + get(rs.getString(5)) + "," + get(rs.getString(6)) + "," + get(rs.getString(7)) + "," + get(rs.getString(8)) + "," + get(rs.getString(9)) + "," + get(rs.getString(10)) + "," + get(rs.getString(11)) + ","

                        + get(rs.getString(12)) + "," + get(rs.getString(13)) + "," + get(rs.getString(14)) + "," + get(rs.getString(15)) + "," + get(rs.getString(16)) + "," + get(rs.getString(17)) + "," + get(rs.getString(18)) + "," + get(rs.getString(19)) + "," + get(rs.getString(20)) + "," + get(rs.getString(21)) + "," + get(rs.getString(22)) + "," + get(rs.getString(23)) + ")");
                    }
                    m.execute(list);
                    System.err.println("从 " + b + "  到  " + a);
                    b = a + 1;
                }

            }
            System.err.println("用时：" + (System.currentTimeMillis() - start));
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static String get(String s) {
        if (s == null || s.trim().equalsIgnoreCase("null")) {
            return null;
        } else {
            return "'" + s.replaceAll("'", "''").replaceAll("\\\\", "\\\\\\\\") + "'";
        }
    }
}